package com.example.chiro;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockActivity;

//Activité principale / Ecran d'accueil
public class Fiches extends SherlockActivity {

	private ListView liste_fiches;
	private Button quitter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.i("t: Fiches", "oC : debut");
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activite_fiches);

		liste_fiches = (ListView) findViewById(R.id.liste_fiches);
		quitter = (Button) findViewById(R.id.quitter_application);

		ArrayList<HashMap<String, String>> liste = new ArrayList<HashMap<String, String>>();

		HashMap<String, String> map;

		map = new HashMap<String, String>();
		map.put("intitule", "Arbre");
		liste.add(map);

		map = new HashMap<String, String>();
		map.put("intitule", "Batiment");
		liste.add(map);

		map = new HashMap<String, String>();
		map.put("intitule", "Grotte");
		liste.add(map);

		map = new HashMap<String, String>();
		map.put("intitule", "Nichoir");
		liste.add(map);

		map = new HashMap<String, String>();
		map.put("intitule", "Ouvrage d\'art");
		liste.add(map);

		SimpleAdapter adapter = new SimpleAdapter(this, liste,
				R.layout.item_fiche, new String[] { "intitule" },
				new int[] { R.id.intitule_fiche });
		liste_fiches.setAdapter(adapter);

		liste_fiches.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				HashMap<String, String> map = (HashMap<String, String>) liste_fiches
						.getItemAtPosition(position);
				Intent intent;
				if (((String) map.get("intitule")).equals("Arbre")) {
					intent = new Intent(Fiches.this, Arbre.class);
					startActivity(intent);
				} else {
					Toast.makeText(
							Fiches.this,
							"La fiche \"" + (String) map.get("intitule")
									+ "\" n'est pas encore disponible !",
							Toast.LENGTH_SHORT).show();
				}
			}
		});
		quitter.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
		Log.i("t: Fiches", "oC : fin");
	}

	protected void onStart() {
		Log.i("t: Fiches", "ooStart");
		super.onStart();
	}

	protected void onRestart() {
		super.onRestart();
		Log.i("t: Fiches", "onRestart");
	}

	protected void onResume() {
		super.onResume();
		Log.i("t: Fiches", "onResume");
	}

	protected void onPause() {
		super.onPause();
		Log.i("t: Fiches", "onPause");
	}

	protected void onStop() {
		super.onStop();
		Log.i("t: Fiches", "onStop");
	}

	protected void onDestroy() {
		super.onDestroy();
		Log.i("t: Fiches", "onDestroy");
	}

}
